
<?php
class PaymentAction extends Action {
	public function wxpay(){
		if(!$_SESSION['login']){
			header('Location:'.U('Login/login'));
			exit;
		}
		
		$enroll_id = $_GET['enroll_id'];
		
		$user_id = $_SESSION['user_id'];
		
		//判断$user_id与$enroll_id是否匹配
		$re = M('Enroll')->where("id=$enroll_id")->find();
		if($re['user_id']!=$user_id){
			header('Location:'.U('User/user_center'));exit;
		}
		$obj = M('Enroll')->where("id=$enroll_id")->find();
		if(!$obj){
			header('Location:'.U('User/user_center'));exit;
		}
		if($obj['state'] == 1){
			header('Location:'.U('Enroll/prompt/enroll_id/'.$enroll_id));exit;
		}
		
		$re = M('Cost')->where('id=1')->find();
		$data['cost']= $re['cost'];
		M('Enroll')->where("id=$enroll_id")->save($data);
		require_once './api/payment/wxpay/wxpay.php';
		$o['goods_name'] = '资料费用';
		$o['order_sn'] = $obj['order_sn'];
 		$o['order_amount'] = $re['cost'];
		$wx = new wxpay($o);
		$wx->get_payurl();
		
	}
}